

import 'dart:io';
import 'package:path_provider/path_provider.dart';

class CYPath {
  // 工厂模式
  factory CYPath() => _getInstance();
  static CYPath get instance => _getInstance();
  static CYPath _instance;

  CYPath._internal() {
    // 初始化
  }
  static CYPath _getInstance() {
    if (_instance == null) {
      _instance = new CYPath._internal();
    }
    return _instance;
  }
  
  Directory _externalStorageDirectory;
  Future<Directory> get extStorageDir async  {
    if(Platform.isIOS) {
      if(_externalStorageDirectory!=null) return _externalStorageDirectory;
      _externalStorageDirectory =  await getApplicationDocumentsDirectory();
      if(!_externalStorageDirectory.existsSync()) {
        _externalStorageDirectory.createSync(recursive: true);
      }
      return _externalStorageDirectory;
    } else {
      if(_externalStorageDirectory!=null) return _externalStorageDirectory;
      _externalStorageDirectory =  await getExternalStorageDirectory();
      if(!_externalStorageDirectory.existsSync()) {
        _externalStorageDirectory.createSync(recursive: true);
      }
      return _externalStorageDirectory;
    }
  }
}
